package com.wc.acwing.区间问题.校门外的树;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/1/15 1:52
 * @description 校门外的树
 * https://www.acwing.com/problem/content/424/
 */

public class Main {
    static FastReader sc = new FastReader();
    static ArrayList<Pair> segs = new ArrayList<>();
    static ArrayList<Pair> res = new ArrayList<>();
    static int l, m;

    public static void main(String[] args) {
        l = sc.nextInt();
        m = sc.nextInt();
        while (m-- > 0) {
            int start = sc.nextInt();
            int end = sc.nextInt();
            segs.add(new Pair(start, end));
        }
        merge();
        for (Pair seg : res) {
            l -= (seg.y - seg.x + 1);
        }
        // 因为有个0的位置的树
        l++;
        System.out.println(l);
    }

    static void merge() {
        segs.sort(Pair::compareTo);
        int st = -1, ed = -1;
        for (Pair seg : segs) {
            if (ed < seg.x) {
                if (st != -1) {
                    res.add(new Pair(st, ed));
                }
                st = seg.x;
                ed = seg.y;
            } else {
                ed = Math.max(ed, seg.y);
            }
        }
        if (st != -1) {
            res.add(new Pair(st, ed));
        }
    }

    static class Pair implements Comparable<Pair> {
        Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }

        int x;
        int y;

        @Override
        public int compareTo(Pair o) {
            if (x == o.x) {
                return y - o.y;
            }
            return x - o.x;
        }
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }
}
